package com.dinetech.dao;

import java.util.ArrayList;

import com.dinetech.ejecutor.DetalleActividad;
import com.dinetech.ejecutor.R;
import com.dinetech.entidades.Actividades;

import android.app.Activity;
import android.content.Context;
import android.opengl.Visibility;
import android.os.AsyncTask;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ItemActividadAdapter extends BaseAdapter {

	protected Activity activity;
	protected ArrayList<Actividades> items;
	
	
	public ItemActividadAdapter(Activity activity, ArrayList<Actividades> items){
		this.activity = activity;
		this.items = items;
	}
	
	@Override
	public int getCount() {
		
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return items.get(position).getIdProgramacion();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		
		if(convertView == null) {
        	LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        	vi = inflater.inflate(R.layout.activity_calendario_listitem, null);
        }
            
        Actividades item = items.get(position);        
        
        TextView hinicio = (TextView) vi.findViewById(R.id.txtInicio);
        TextView hfin = (TextView) vi.findViewById(R.id.txtFin);
        TextView nombreActividad = (TextView) vi.findViewById(R.id.txtDetActividad);
        TextView galpones = (TextView) vi.findViewById(R.id.txtCalendarioGalpones);
        ImageView img = (ImageView) vi.findViewById(R.id.imgActvidadOK);
        
        if(item.getIdProgramacion() > 0){
	        
	        hinicio.setText(item.getHoraInicio());	        	        
	        hfin.setText(item.getHoraFin());	        	       
	        nombreActividad.setText(item.getNomActividad());
	        galpones.setText(item.getDetalleGalpones());

	        
	        if(item.getEstadoActividad().equals("T")){	        
		        img.setVisibility(View.VISIBLE);
	        }else{
	        	img.setVisibility(View.INVISIBLE);
	        }
        }else{   
        	LinearLayout lh = (LinearLayout)vi.findViewById(R.id.linearHoraActividades);
        	lh.setVisibility(View.INVISIBLE);
	        nombreActividad.setText(item.getNomActividad());
	        //hinicio.setVisibility(View.INVISIBLE);
	        //hfin.setVisibility(View.INVISIBLE);
	        galpones.setVisibility(View.INVISIBLE);
	        
        }
        	
        return vi;

	}
	
	
}
